package org.openrbac.rbac.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 系统菜单
 * @TableName auth
 */
@TableName(value ="auth")
@Data
public class Auth implements Serializable {
    /**
     * ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 上级权限ID
     */
    @TableField(value = "pid")
    private Long pid;

    /**
     * 下级权限数目
     */
    @TableField(value = "count_sub")
    private Integer countSub;

    /**
     * 前端菜单显示的排序
     */
    @TableField(value = "sort")
    private Integer sort;

    /**
     * 前端菜单类型:0-顶部菜单；1-一级菜单；2-子菜单；3-页面资源；4-外联
     */
    @TableField(value = "type")
    private String type;

    /**
     * 菜单（路由）名称
     */
    @TableField(value = "name")
    private String name;

    /**
     * 菜单（路由）地址：user/page
     */
    @TableField(value = "path")
    private String path;

    /**
     * 菜单（路由）父级映射地址：user/page
     */
    @TableField(value = "redirect")
    private String redirect;

    /**
     * 菜单（路由）组件：components/icons/index
     */
    @TableField(value = "component")
    private String component;

    /**
     * 菜单（路由）图标
     */
    @TableField(value = "meta_icon")
    private String metaIcon;

    /**
     * 菜单（路由）标题
     */
    @TableField(value = "meta_title")
    private String metaTitle;

    /**
     * 菜单权限：user:page
     */
    @TableField(value = "permission")
    private String permission;

    /**
     * 微服务模块名称
     */
    @TableField(value = "module")
    private String module;

    /**
     * 后端controller地址
     */
    @TableField(value = "uri")
    private String uri;

    /**
     * 外链链接
     */
    @TableField(value = "href")
    private String href;

    /**
     * 是否隐藏：1-删除；0-未删除
     */
    @TableField(value = "is_hidden")
    private Boolean isHidden;

    /**
     * 是否逻辑删除：1-删除；0-未删除
     */
    @TableField(value = "is_deleted")
    @TableLogic
    private Boolean isDeleted;

    /**
     * 创建者
     */
    @TableField(value = "create_by")
    private String createBy;

    /**
     * 更新者
     */
    @TableField(value = "update_by")
    private String updateBy;

    /**
     * 创建日期
     */
    @TableField(value = "create_time")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date createTime;

    @TableField(exist = false)
    private List<Auth> children;

    /**
     * 更新时间
     */
    @TableField(value = "update_time")
    private Date updateTime;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Auth other = (Auth) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getPid() == null ? other.getPid() == null : this.getPid().equals(other.getPid()))
            && (this.getCountSub() == null ? other.getCountSub() == null : this.getCountSub().equals(other.getCountSub()))
            && (this.getSort() == null ? other.getSort() == null : this.getSort().equals(other.getSort()))
            && (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
            && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
            && (this.getPath() == null ? other.getPath() == null : this.getPath().equals(other.getPath()))
            && (this.getRedirect() == null ? other.getRedirect() == null : this.getRedirect().equals(other.getRedirect()))
            && (this.getComponent() == null ? other.getComponent() == null : this.getComponent().equals(other.getComponent()))
            && (this.getMetaIcon() == null ? other.getMetaIcon() == null : this.getMetaIcon().equals(other.getMetaIcon()))
            && (this.getMetaTitle() == null ? other.getMetaTitle() == null : this.getMetaTitle().equals(other.getMetaTitle()))
            && (this.getPermission() == null ? other.getPermission() == null : this.getPermission().equals(other.getPermission()))
            && (this.getModule() == null ? other.getModule() == null : this.getModule().equals(other.getModule()))
            && (this.getUri() == null ? other.getUri() == null : this.getUri().equals(other.getUri()))
            && (this.getHref() == null ? other.getHref() == null : this.getHref().equals(other.getHref()))
            && (this.getIsHidden() == null ? other.getIsHidden() == null : this.getIsHidden().equals(other.getIsHidden()))
            && (this.getIsDeleted() == null ? other.getIsDeleted() == null : this.getIsDeleted().equals(other.getIsDeleted()))
            && (this.getCreateBy() == null ? other.getCreateBy() == null : this.getCreateBy().equals(other.getCreateBy()))
            && (this.getUpdateBy() == null ? other.getUpdateBy() == null : this.getUpdateBy().equals(other.getUpdateBy()))
            && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
            && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getPid() == null) ? 0 : getPid().hashCode());
        result = prime * result + ((getCountSub() == null) ? 0 : getCountSub().hashCode());
        result = prime * result + ((getSort() == null) ? 0 : getSort().hashCode());
        result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
        result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
        result = prime * result + ((getPath() == null) ? 0 : getPath().hashCode());
        result = prime * result + ((getRedirect() == null) ? 0 : getRedirect().hashCode());
        result = prime * result + ((getComponent() == null) ? 0 : getComponent().hashCode());
        result = prime * result + ((getMetaIcon() == null) ? 0 : getMetaIcon().hashCode());
        result = prime * result + ((getMetaTitle() == null) ? 0 : getMetaTitle().hashCode());
        result = prime * result + ((getPermission() == null) ? 0 : getPermission().hashCode());
        result = prime * result + ((getModule() == null) ? 0 : getModule().hashCode());
        result = prime * result + ((getUri() == null) ? 0 : getUri().hashCode());
        result = prime * result + ((getHref() == null) ? 0 : getHref().hashCode());
        result = prime * result + ((getIsHidden() == null) ? 0 : getIsHidden().hashCode());
        result = prime * result + ((getIsDeleted() == null) ? 0 : getIsDeleted().hashCode());
        result = prime * result + ((getCreateBy() == null) ? 0 : getCreateBy().hashCode());
        result = prime * result + ((getUpdateBy() == null) ? 0 : getUpdateBy().hashCode());
        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", pid=").append(pid);
        sb.append(", count_sub=").append(countSub);
        sb.append(", sort=").append(sort);
        sb.append(", type=").append(type);
        sb.append(", name=").append(name);
        sb.append(", path=").append(path);
        sb.append(", redirect=").append(redirect);
        sb.append(", component=").append(component);
        sb.append(", meta_icon=").append(metaIcon);
        sb.append(", meta_title=").append(metaTitle);
        sb.append(", permission=").append(permission);
        sb.append(", module=").append(module);
        sb.append(", uri=").append(uri);
        sb.append(", href=").append(href);
        sb.append(", is_hidden=").append(isHidden);
        sb.append(", is_deleted=").append(isDeleted);
        sb.append(", create_by=").append(createBy);
        sb.append(", update_by=").append(updateBy);
        sb.append(", create_time=").append(createTime);
        sb.append(", update_time=").append(updateTime);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}